package com.emagic.manage.data.db.entry;

import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;

import java.io.File;
import java.util.List;

/**
 * 离线数据
 * Created by xiatian on 2017/8/14.
 */

@Entity
public class OfflineData implements Parcelable {

    public static final int NOTHING = 0;        //默认状态
    public static final int WATTING = 1;        //正在等待
    public static final int RUNNING = 2;        //正在执行
    public static final int CANCEL = 3;         //已取消
    public static final int ERROR = 4;          //错误
    public static final int FINISHED = 5;       //已完成

    @Id
    private Long id;
    private Long userId, communityId;//用户 id,市区 id
    private String communityName;   //社区名称
    private String state;           //服务端下载状态 0:未下载 1:需要更新 2:不需要更新
    private String lasttime;        //最后下载时间
    private String downloadaddr;    //文件下载地址

    //客户端使用字段
    private String localPath;        //文件落地地址
    private String ossObjKey;        //文件 OSS key
    private String downloadTime;     //下载时间
    private int taskState;           //任务状态


    @Transient
    private File localFile;
    @Transient
    private List<File> zipFiles;    //压缩包里的文件
    @Transient
    private List<DeviceInfo> deviceInfos;
    @Transient
    private List<DeviceType> deviceTypes;
    @Transient
    private List<InspectItem> inspectItems;
    @Transient
    private List<MaintainItem> maintainItems;

    @Generated(hash = 930856436)
    public OfflineData(Long id, Long userId, Long communityId, String communityName,
                       String state, String lasttime, String downloadaddr, String localPath,
                       String ossObjKey, String downloadTime, int taskState) {
        this.id = id;
        this.userId = userId;
        this.communityId = communityId;
        this.communityName = communityName;
        this.state = state;
        this.lasttime = lasttime;
        this.downloadaddr = downloadaddr;
        this.localPath = localPath;
        this.ossObjKey = ossObjKey;
        this.downloadTime = downloadTime;
        this.taskState = taskState;
    }

    @Generated(hash = 2100497485)
    public OfflineData() {
    }

    protected OfflineData(Parcel in) {
        id = in.readLong();
        userId = in.readLong();
        communityId = in.readLong();
        communityName = in.readString();
        state = in.readString();
        lasttime = in.readString();
        downloadaddr = in.readString();
        localPath = in.readString();
        ossObjKey = in.readString();
        downloadTime = in.readString();
        taskState = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeLong(userId);
        dest.writeLong(communityId);
        dest.writeString(communityName);
        dest.writeString(state);
        dest.writeString(lasttime);
        dest.writeString(downloadaddr);
        dest.writeString(localPath);
        dest.writeString(ossObjKey);
        dest.writeString(downloadTime);
        dest.writeInt(taskState);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<OfflineData> CREATOR = new Creator<OfflineData>() {
        @Override
        public OfflineData createFromParcel(Parcel in) {
            return new OfflineData(in);
        }

        @Override
        public OfflineData[] newArray(int size) {
            return new OfflineData[size];
        }
    };

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return this.userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getCommunityId() {
        return this.communityId;
    }

    public void setCommunityId(Long communityId) {
        this.communityId = communityId;
    }

    public String getCommunityName() {
        return this.communityName;
    }

    public void setCommunityName(String communityName) {
        this.communityName = communityName;
    }

    public String getState() {
        return this.state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getLasttime() {
        return this.lasttime;
    }

    public void setLasttime(String lasttime) {
        this.lasttime = lasttime;
    }

    public String getDownloadaddr() {
        return this.downloadaddr;
    }

    public void setDownloadaddr(String downloadaddr) {
        this.downloadaddr = downloadaddr;
    }

    public String getDownloadTime() {
        return this.downloadTime;
    }

    public void setDownloadTime(String downloadTime) {
        this.downloadTime = downloadTime;
    }

    public String getLocalPath() {
        return this.localPath;
    }

    public void setLocalPath(String localPath) {
        this.localPath = localPath;
    }

    public int getTaskState() {
        return this.taskState;
    }

    public void setTaskState(int taskState) {
        this.taskState = taskState;
    }

    public String getOssObjKey() {
        return this.ossObjKey;
    }

    public void setOssObjKey(String ossObjKey) {
        this.ossObjKey = ossObjKey;
    }


    public List<File> getZipFiles() {
        return zipFiles;
    }

    public void setZipFiles(List<File> zipFiles) {
        this.zipFiles = zipFiles;
    }

    public List<DeviceInfo> getDeviceInfos() {
        return deviceInfos;
    }

    public void setDeviceInfos(List<DeviceInfo> deviceInfos) {
        this.deviceInfos = deviceInfos;
    }

    public List<DeviceType> getDeviceTypes() {
        return deviceTypes;
    }

    public void setDeviceTypes(List<DeviceType> deviceTypes) {
        this.deviceTypes = deviceTypes;
    }

    public List<InspectItem> getInspectItems() {
        return inspectItems;
    }

    public void setInspectItems(List<InspectItem> inspectItems) {
        this.inspectItems = inspectItems;
    }

    public List<MaintainItem> getMaintainItems() {
        return maintainItems;
    }

    public void setMaintainItems(List<MaintainItem> maintainItems) {
        this.maintainItems = maintainItems;
    }

    public File getLocalFile() {
        return localFile;
    }

    public void setLocalFile(File localFile) {
        this.localFile = localFile;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        OfflineData that = (OfflineData) o;

        return id.equals(that.id);

    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
